package edu.demo.recommend.common;

import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;

import java.util.List;

/**
 * @author hb
 */
public class CommonUtils {

    public static String processErrorMessage(BindingResult bindingResult){
        if(!bindingResult.hasErrors()){
            return "";
        }
        List<FieldError> fieldErrors = bindingResult.getFieldErrors();
        StringBuilder sb = new StringBuilder();
        fieldErrors.forEach(e->  sb.append(e.getDefaultMessage()+",") );

        return sb.substring(0, sb.length() - 1);

    }
}
